package com.onion.orm.service;

import com.alibaba.fastjson.JSON;
import com.onion.orm.dao.EnhancedDao;
import com.onion.orm.entity.AppInfo;
import com.onion.orm.support.command.DynamicQueryFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Component("appInfoService")
public class AppInfoService {

    private Logger logger = LoggerFactory.getLogger(AppInfoService.class);

    @Resource
    EnhancedDao<AppInfo, String> appInfoEnhancedDao;

    @Transactional
    public void test(){
        AppInfo appInfo = appInfoEnhancedDao.get("appCode", "app1001");
        appInfo.setRemark("测试MyBatis缓存...");
        //appInfoEnhancedDao.update(appInfo);
        AppInfo appInfo2 = appInfoEnhancedDao.get("onion-hunter");
        logger.info("AppInfo:{}", JSON.toJSONString(appInfo2));
    }

    public void test2(){
        DynamicQueryFilter queryFilter = new DynamicQueryFilter();
        appInfoEnhancedDao.find(queryFilter.getQueryData());
    }

}
